<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2024/8/16
  Time: 9:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%
        String base = request.getContextPath() + "/";
        String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + base;
    %>
    <base href="<%=url%>">
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var bid = $("[name='hitxt']").val();
            $.get("book/queryById", {"bookId": bid}, function (book) {
                JSON.stringify(book);
                $("[name='BookName']").val(book.bookName);
                $("[name='BookAuthor']").val(book.bookAuthor);
                $("[name='BookPublish']").val(book.bookPublish);
                $("[name='BookPage']").val(book.bookPage);
                $("[name='BookPrice']").val(book.bookPrice);
                $("[name='CreateDate']").val(book.createDate);
            });
            //窗体加载后点提交按钮单击事件发送异步请求
            $("[type='button']").click(function () {
                var bname = $("[name='BookName']").val();
                var aname = $("[name='BookAuthor']").val();
                var cname = $("[name='BookPublish']").val();
                var page = $("[name='BookPage']").val();
                var price = $("[name='BookPrice']").val();
                var date = $("[name='CreateDate']").val();
                $.get("book/update", {
                    "bid":bid,
                    "bname": bname,
                    "aname": aname,
                    "cname": cname,
                    "page": page,
                    "price": price,
                    "date": date
                }, function (mess) {
                    JSON.stringify(mess);
                    if (mess) {
                        alert("修改成功");
                    } else {
                        alert("修改失败")
                    }
                })
            });

        });
    </script>
</head>
<body>
<a href="index.jsp">返回</a>
<h1>更改图书</h1>

书名：<input type="text" name="BookName"><br>
作者：<input type="text" name="BookAuthor"><br>
出版社：<input type="text" name="BookPublish"><br>
页数：<input type="text" name="BookPage"><br>
价格：<input type="text" name="BookPrice"><br>
时间：<input type="date" name="CreateDate"><br>
<input type="button" value="更改">
<input type="hidden" name="hitxt" value="<%=request.getParameter("bookId")%>"/>
</body>
</html>
